<?php
/**
 * 操作用户信息
 * User: 老毛
 * Date: 2019/9/4
 * Time: 10:03
 */

namespace app\api\controller;
use function PHPSTORM_META\type;
use think\Db;
use think\Validate;
use app\api\logic\Sms;
class NoTokenData extends Base
{
    //获取新人帮助列表
    public function getnewpeople(){
        //获取首页广告标题
        $bangzhu = Db::name('php_articles')->where(['status' => 1,'cid' => 9])->select();
        if(!$bangzhu)  return ajaxReturn('内容获取失败！',99);
         return ajaxReturn('成功！',1,$bangzhu);
    }
    //获取用户个人信息
    public function getuserinfodata(){
        $get = $_GET;
        if(!isset($get['uid']) && !isset($get['page'])) return ajaxReturn('获取失败！',99);
        if($get['page'] == 1){
            //个人头像性别名称等
            $user = Db::name('php_member')->where(['id' => $get['uid']])->find();
            if(!$user) return ajaxReturn('获取失败！',99);
            $sexQ = ['保密','男','女'];
            $user['sex'] = $sexQ[$user['sex']];
            $user['image'] = WEB_URL.'/'.$user['image'];
        }else{
            $user = [];
        }
        //获取个人发圈列表
        $data = Db::name('php_quanzhi')->where(['status' => 0,'uid' => $get['uid']])->order('id desc')->page($get['page'],10)->select();
        //将查询出来的数据里面的图片 改为数组
        foreach ($data as $k => $v){
           if($v['image']){
               $data[$k]['imageall'] = explode('|',$v['image']);
               foreach ($data[$k]['imageall'] as $key=>$value){
                   $data[$k]['imageall'][$key] = WEB_URL.'/'.$value;
               }
           }
        }
        if(!is_array($data) && !is_array($user)) return ajaxReturn('错误',99);
        $res = ['user' => $user,'quanzhi' => $data];
        if(count($data) > 0){
            return ajaxReturn('获取成功',1,$res);
        }else{
            return ajaxReturn('这个已经是最后一页啦',2,$res);
        }
    }

    //上传图片
    public function setUpdata(){
        $file = $_FILES;
        if(!isset($file['file'])) return ajaxReturn('上传失败',999);
        $data = setFile($file['file']);
        if(!$data) return ajaxReturn('上传失败',999);
        return ajaxReturn('上传成功',1,$data);
    }


    //获取商家分类
    public function getStoreCate(){
        $data = Db::name('php_mcate')->select();
        if(!$data)  return ajaxReturn('暂无分类',99);
        return ajaxReturn('获取成功',1,$data);
    }
}